#e
#Title[vuZՂbv]
#Text[]
#Image[]
#BackGround[]
#BGM[]
#PlayLevel[Extra]
#ScriptVersion[2]
#Player[FREE]

script_enemy_main
{
let wt=50;
let usebomb=0;

	//GoɈxs镔
	@Initialize
	{
	//   eϐ

	//   XyJ[hf[^
	SetLife(1000);
	SetScore(200000);
	SetDamageRate(30,  0);
	SetTimer(80);
	SetInvincibility(250);
	SetShotAutoDeleteClip(64,128,64,64);
	LoadGraphic("script\img\ExRumia.png");
	LoadUserShotData(GetCurrentScriptDirectory~"..\img\usershot.txt");
	CutIn(KOUMA,"vuZՂbv",GetCurrentScriptDirectory~"..\img\cutin03.png",0,0,255,320);

	}
	//   ʒu܂ňړ
	SetMovePosition02(GetCenterX, GetClipMinY+80, 60);

	BG_Standard;
	AtackTask;
	MoveTask;
	ControlTask;
	//G̃Ct0ɂȂ܂ŁA̕1t[1s
	@MainLoop
	{
		yield;


		if(OnBomb==false){
			SetCollisionA(GetX, GetY, 32);
			SetCollisionB(GetX, GetY, 24);
			usebomb=0;
		}
		else{
			usebomb++;
		}
		if(usebomb==1){
			BombBarrier;
		}
	}
	
	//`惋[vB1t[1s
	@DrawLoop
	{
		SetGraphicRect(0,1,63,64);
		if(GetSpeedX<0){
			SetGraphicRect(128,1,191,64);
		}
		if(GetSpeedX>0){
			SetGraphicRect(192,1,255,64);
		}
		SetColor(255,255,255);
		SetAlpha(255);
		if(OnBomb==true){SetAlpha(96);}
		SetTexture("script\img\ExRumia.png");//摜͔q
		DrawGraphic(GetX(),GetY());//G̍WEx[~A`;
	}
		
	//GłuԂɈxs镔
	@Finalize
	{
		DeleteGraphic("script\img\ExRumia.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back1.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back2.png");
	}
	//XyJ[h̔wi
	//Ă悢
	@BackGround
	{
		BG_Simple;
	}

	task AtackTask{
		wait(120);
		CreateLaserA(0,GetClipMinX+10,GetClipMinY-50,500,20,21,30);
		SetLaserDataA(0,0,90,0,0,0,0);
		FireShot(0);
		CreateLaserA(0,GetClipMaxX-10,GetClipMinY-50,500,20,21,30);
		SetLaserDataA(0,0,90,0,0,0,0);
		FireShot(0);

		let noshot=rand_int(1,5);
		loop{
			ascent(i in 1..6){
				if(i!=noshot){
					Tama(i*71+12,GetClipMinY,3,YELLOW05,20);
				}
			}
			wait(wt);
			alternative(noshot)
			case(1){
				noshot=rand_int(2,3);
			}
			case(2){
				while(noshot==2){
					noshot=rand_int(1,4);
				}
			}
			case(3){
				while(noshot==3){
					noshot=rand_int(1,5);
				}
			}
			case(4){
				while(noshot==4){
					noshot=rand_int(2,5);
				}
			}
			case(5){
				noshot=rand_int(3,4);
			}

		}

	}
	task Tama(	//ZՂ̎^1
		x,	//W
		y,
		spd,
		grf,
		delay
	){
		let xplus=0;
		let xadd=5.3;
		loop(6){
			CreateShot01(x,y,spd,90,grf,delay);
			CreateShot01(x+xplus,y,spd,90,grf,delay);
			CreateShot01(x-xplus,y,spd,90,grf,delay);
			xplus+=xadd;
			y-=xadd;
		}
		loop(4){
			CreateShot01(x,y,spd,90,grf,delay);
			CreateShot01(x+xplus,y,spd,90,grf,delay);
			CreateShot01(x-xplus,y,spd,90,grf,delay);
			y-=xadd;
		}
		loop(7){
			CreateShot01(x,y,spd,90,grf,delay);
			CreateShot01(x+xplus,y,spd,90,grf,delay);
			CreateShot01(x-xplus,y,spd,90,grf,delay);
			xplus-=xadd;
			y-=xadd;
		}

	}

	task MoveTask{		//@Ɉړp^[
		wait(240);
		while(true){
			let ptn=0;
			if(GetX<GetCenterX-80){ptn=1;}
			if(GetX>GetCenterX+80){ptn=2;}
			if(ptn==0){
				if(GetX<GetPlayerX){ptn=1;}
				else{ptn=2;}
			}
			if(ptn==1){
				SetMovePosition02(rand(GetX+40,GetX+60), rand(GetClipMinY+40,GetClipMinY+120), 40);
			}
			if(ptn==2){
				SetMovePosition02(rand(GetX-40,GetX-60), rand(GetClipMinY+40,GetClipMinY+120), 40);
			}
			wait(80);
		}
	}

	task ControlTask{
		wait(250);
		while(GetEnemyLife>800&&GetTimer>20){yield;}
		wt=48;
		while(GetEnemyLife>600&&GetTimer>20){yield;}
		wt=46;
		while(GetEnemyLife>400&&GetTimer>20){yield;}
		wt=44;
		while(GetEnemyLife>200&&GetTimer>20){yield;}
		wt=42;
		while(GetTimer>20){yield;}
		wt=40;
	}

	#include_function".\function.txt"
}

